//
//  ValidBankListEngine.m
//  HuLaQuan
//
//  Created by hok on 1/28/16.
//  Copyright © 2016 Jianghao. All rights reserved.
//

#import "ValidBankListEngine.h"

#import "CurrentUser.h"

@implementation ValidBankListEngine
- (void)getValidBankList
{
    NSString *loginSrc = [NSString stringWithFormat: @"<?xml version=\"1.0\" encoding=\"UTF-8\"?><msg service=\"supBank\" sysName=\"attach\" sign=\"RSA\" serialNumber=\"%@\" termId=\"star_open_esa\" termAdd=\"23.23,23.45\" termBrand=\"iPhone\" osVersion=\"iPhone OS 9.1\" appVersion=\"1.0.0\" tokenValue=\"%@\" userId=\"%@\" channelId=\"88888888\"><attach>attach</attach></msg>",[self getSerialNumber],[CurrentUser sharedInstance].token,[CurrentUser sharedInstance].ID];
    //
    NSString *randomKey = [self createKeyWithLength:24];
    
    NSLog(@"%@ -- src ---%@ key ",loginSrc,randomKey);
    
    
    NSString *first =[self firstString];
    
    NSString *second = [self secondStringWithKey:randomKey];
    NSString *third = [self thirdStringWithBody:loginSrc andKey:randomKey];
    NSString *final = [NSString stringWithFormat:@"%@|%@|%@",first,second,third];
    
    NSLog(@"%@",final);
    [YuHTTPClient XMLDataWithUrl:SERVER_HOST_CASHIER parameters:final success:^(BOOL isSuccess, id item){
        
        NSDictionary *result;
        if (isSuccess) {
            if ([item isKindOfClass:[NSArray class]]) {
                NSString *resString = [_DES decrypt:[item lastObject] withKey:randomKey];
                
                NSDictionary *resultDic = [self parseXMLFromYinLianConnection:resString];
                NSLog(@"%@ %@",resString ,resultDic);
                
                result = @{@"isSuccess":@YES,@"result":resultDic[@"list"][@"supBank"]};
                
            }
            
        }else{
            
            result = @{@"isSuccess":@NO,@"message":item};
            NSLog(@"%@",result);
        }
        
        [[NSNotificationCenter defaultCenter] postNotificationName:@"GetValidBankListFinish" object:result];
    }];

}
@end
